class Sunshroom extends GuaAnimation {
    static new(game) {
        let p = new this(game, animationSunshroom)
        p.setup()
        return p
    }

    setup() {
        // row表示在草地的第几排
        this.row = -1
        this.cooldown = 200
        this.score = 25
        this._sleep = true
        this.status = 400
    }

    awake() {
        this._sleep = false
        this.changeAnimation('idle')
    }

    sleep() {
        this._sleep = true
    }

    remove() {
        this.scene.removeFlower(this)
    }

    creatSun() {
        // 睡眠状态不产生阳光
        if (this._sleep) {
            return
        }
        this.cooldown--
        if (this.cooldown === 0) {
            // 开始冷却
            this.cooldown = 200
            // 生成阳光
            let s = this.game.scene
            let pb = Sun.new(this.game)
            pb.row = this.row
            pb.column = this.column
            pb.x = this.x
            pb.y = this.y
            pb.k = (pb.x - pb.gx) / pb.speed
            pb.ky = (pb.y - pb.gy) / pb.k

            this.game.scene.addElement(pb)
            s.addElement(pb)
            s.suns.push(pb)
        }
    }

    update() {
        super.update()
        if (this._sleep) {
            this.status--
            if (this.status === 0) {
                this.awake()
            }
        }
        this.creatSun()
    }
}